package com.danielepelagatti.flickrmanager.vo
{
	import com.adobe.cairngorm.vo.IValueObject;
	import com.danielepelagatti.flickrmanager.events.UploadVOEvent;
	
	import flash.events.DataEvent;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	import flash.events.SecurityErrorEvent;
	import flash.filesystem.File;
	import flash.net.FileReference;
	
	import mx.collections.ArrayCollection;
	import com.danielepelagatti.flickrmanager.model.Flickr;
	[Bindable]
	/**
	 * 
	 * @author dpelagatti
	 * 
	 */	
	public class UploadVO extends EventDispatcher implements IValueObject
	{
		[Event(name="upload_complete_data",type="flash.events.DataEvent")]
		[Event(name="cancel",type="flash.events.Event")]
		[Event(name="fault",type="mx.rpc.events.FaultEvent")]
		
		
		public static const MULTIPLE_TITLES:String 			= "Multiple Titles...";
		public static const MULTIPLE_DESCRIPTIONS:String 	= "Multiple Descriptions...";
		public static const MULTIPLE_TAGS:String 			= "Multiple Tags...";
		public static const UPLOAD_CANCEL:String			= "upload_cancel";
		public var isCompleted:Boolean = false;
		
		private var _file:File;
		private var _title:String = "";
		private var _description:String = "";
		private var _tags:String = "";
		private var _is_public:Boolean = true;
		private var _is_friend:Boolean = false;
		private var _is_family:Boolean = false;
		
		public function cancel():void
		{
			isCompleted = true;
			var e:Event = new Event(UPLOAD_CANCEL);
			dispatchEvent(e);			
		}
		/**
		 * 
		 * @param event
		 * 
		 */		
		protected function completeHandler(event:DataEvent):void
		{
			isCompleted = true;
			var e:DataEvent = new DataEvent(DataEvent.UPLOAD_COMPLETE_DATA);
			dispatchEvent(e);
		}
		/**
		 * 
		 * @param event
		 * 
		 */		
		protected function progressHanlder(event:ProgressEvent):void
		{
			var e:ProgressEvent = new ProgressEvent(ProgressEvent.PROGRESS);
			e.bytesLoaded = event.bytesLoaded;
			e.bytesTotal = event.bytesTotal;
			dispatchEvent(e);
		}
		/**
		 * 
		 * @param event
		 * 
		 */		
		protected function faultHandler(event:Event):void
		{
			var e:Event = new Event("fault");
			dispatchEvent(e);
		}
		/**
		* The File that the user "browsed" to so that upload works correctly. 	
		*/
		public function set file(value:File):void
		{
			_file = value;
			
			dispatchEvent(new UploadVOEvent(UploadVOEvent.PROP_CHANGE,"file"));
			
			_file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA		, completeHandler);
			_file.addEventListener(ProgressEvent.PROGRESS				, progressHanlder);
			_file.addEventListener(SecurityErrorEvent.SECURITY_ERROR	, faultHandler);
			_file.addEventListener(IOErrorEvent.IO_ERROR				, faultHandler);	
		}
		public function get file():File
		{
			return _file;
		}
		
		/**
		* (Optional) The title of the photo.
		*/
		public function set title(value:String):void
		{
			_title = value;
			//dispatchEvent(new UploadVOEvent(UploadVOEvent.PROP_CHANGE,"title"));
		}
		public function get title():String
		{
			return _title;
		}
		
		/**
		* (Optional) A description of the photo. May contain some limited HTML.
		*/
		public function set description(value:String):void
		{
			_description = value;
			//dispatchEvent(new UploadVOEvent(UploadVOEvent.PROP_CHANGE,"description"));
		}
		public function get description():String
		{
			return _description;
		}
		
		/**
		* (Optional) Collection of tags to apply to the photo.
		*/
		public function set tags(value:String):void
		{
			_tags = value;
			//dispatchEvent(new UploadVOEvent(UploadVOEvent.PROP_CHANGE,"tags"));
		}
		public function get tags():String
		{
			return _tags;
		}
		
		/**
		* (Optional) True if the photo is public, false otherwise
		*/
		public function set is_public(value:Boolean):void
		{
			_is_public = value;
			//dispatchEvent(new UploadVOEvent(UploadVOEvent.PROP_CHANGE,"is_public"));
		}
		public function get is_public():Boolean
		{
			return _is_public;
		}
		
		/**
		* (Optional) True if the photo should be marked for friends, false otherwise
		*/
		public function set is_friend(value:Boolean):void
		{
			_is_friend = value;
			//dispatchEvent(new UploadVOEvent(UploadVOEvent.PROP_CHANGE,"is_friend"));
		}
		public function get is_friend():Boolean
		{
			return _is_friend;
		}
		
		/**
		* (Optional) True if the photo should be marked for family access only, false otherwise
		*/
		public function set is_family(value:Boolean):void
		{
			_is_family = value;
			//dispatchEvent(new UploadVOEvent(UploadVOEvent.PROP_CHANGE,"is_family"));
		}
		public function get is_family():Boolean
		{
			return _is_family;
		}				
		
	}
}